home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.10 Oct 90 / NewToolBox.π / Demo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-02  |  4.1 KB  |  231 lines  |  [TEXT/KAHL]

  1. /*
  2. ----------- D E M O  . C
  3.  
  4.             May 1989 - HA OLIVER
  5. */
  6.  
  7.  
  8. #include "Demo.h"
  9.  
  10. /*
  11. ---------------------- Globals...
  12. */
  13.  
  14. TEHandle    CurrentText;
  15. ListHandle    CurrentList;
  16. WindowPtr    CurrentPort;
  17. Handle        ListList,TextList,PictList;
  18. SysEnvRec    theWorld;
  19. MenuHandle    myMenus[LastMenu];
  20. CursHandle    IbeamHdl,WatchHdl,PlusHdl,CrossHdl;
  21. Cursor        Ibeam,Watch,Plus,Cross;
  22. Boolean        MultiFinder,notFinished=TRUE,isDoc=FALSE;
  23. EventRecord    Event;    
  24. char        theChar;
  25. Rect        dragRect = { 0, 0, 1024, 1024 },growRect = { 0, 0, 1024, 1024 };
  26.  
  27.  
  28. /*
  29. ---------------------- SetUp the Cursors
  30. */
  31.  
  32. SetUpCursor()
  33. {
  34.     WatchHdl    =GetCursor(watchCursor);
  35.     IbeamHdl    =GetCursor(iBeamCursor);
  36.     CrossHdl    =GetCursor(crossCursor);
  37.     PlusHdl        =GetCursor(plusCursor);
  38.     Watch        =**WatchHdl;
  39.     Ibeam        =**IbeamHdl;
  40.     Cross        =**CrossHdl;
  41.     Plus        =**PlusHdl;
  42. }
  43.  
  44. /*
  45. ----------------------  Set Up the Menu Bar
  46. */
  47.     
  48. SetUpMenus()
  49. {
  50.     register    int    i;
  51.     
  52.     myMenus[1] = GetMenu(AppleM);
  53.     myMenus[2] = GetMenu(FileM);
  54.     for ( (i=1); (i<=LastMenu); i++ ) InsertMenu(myMenus[i], 0);
  55.     DrawMenuBar();    
  56. }
  57.  
  58. /*
  59. ----------------------  SetUp the System
  60. */
  61.  
  62. SetUpSystem()
  63. {
  64.     InitGraf(&thePort);
  65.     InitFonts();
  66.     InitWindows();
  67.     InitMenus();
  68.     TEInit();
  69.     InitDialogs(NULL);
  70.     InitAllPacks();
  71.     InitCursor();
  72.     MaxApplZone();
  73.     MoreMasters();
  74.     MoreMasters();
  75.     MoreMasters();
  76.     MoreMasters();
  77.     MoreMasters();
  78.     FlushEvents(everyEvent,0);
  79. }
  80.  
  81. /*
  82. ---------------------- SetUp some Variables ...
  83. */
  84.  
  85. SetUpVariables()
  86. {    
  87.     CurrentText        =NULL;
  88.     CurrentList        =NULL;
  89.     if (GetTrapAddress(WaitNextEventTrap)==GetTrapAddress(UnImplementedTrap))
  90.         MultiFinder=FALSE;
  91.     else
  92.         MultiFinder=TRUE;
  93.     if (SysEnvirons(1,&theWorld)!=envNotPresent)
  94.         {
  95.         }
  96.     else notFinished=FALSE;
  97. }
  98.  
  99. /*
  100. ---------------------- Adjust Cursor form
  101. */
  102.  
  103. MaintainCursor()
  104. {
  105.             WindowPtr    theWindow;
  106.             Point        pt,newOr;
  107.             Rect        contRect;
  108.             Cursor        theCursor;
  109.             Boolean        changed;
  110.     
  111.     changed     =FALSE;
  112.     theWindow=FrontWindow();
  113.     GetPort(&CurrentPort);
  114.     SetPort(theWindow);
  115.     GetWindowClip(&contRect,&newOr,theWindow);
  116.     OffsetRect(&contRect,newOr.h,newOr.v);
  117.     GetMouse(&pt);
  118.     if (PtInRect(pt,&contRect))
  119.         {
  120.             ClipRect(&contRect);
  121.             SetOrigin(newOr.h,newOr.v);
  122.                 if (FindText(pt,theWindow)!=NULL)
  123.                     { theCursor=Ibeam;
  124.                       changed  =TRUE;
  125.                      }
  126.                 if (FindList(false,pt,theWindow)!=NULL)
  127.                     { theCursor=Plus;
  128.                       changed  =TRUE;
  129.                      }
  130.         }
  131.     if (changed)
  132.         SetCursor(&theCursor);
  133.     else
  134.         SetCursor(&arrow);
  135.     SetPort(CurrentPort);
  136. }
  137.  
  138. /*
  139. ---------------------- How many bytes are free ?
  140. */
  141.  
  142. CheckMemory()
  143. {    
  144. }
  145.  
  146. /*
  147. ---------------------- Adjust all Menus
  148. */
  149.  
  150. MaintainMenu()
  151. {
  152. }
  153.  
  154. /*
  155. ---------------------- The Event Loop !
  156. */
  157.  
  158. doLoop()
  159. {
  160.     WindowPtr    inWindow;
  161.     int            where;
  162.     Boolean        eventOK;
  163.     
  164.     SystemTask();
  165.     if (CurrentText!=NULL) TEIdle(CurrentText);
  166.     if (isDoc) MaintainCursor();
  167.     MaintainMenu();
  168.     CheckMemory();
  169.     
  170.     if (MultiFinder) 
  171.         eventOK=WaitNextEvent(everyEvent,&Event,sleep,NULL);
  172.     else
  173.         eventOK=GetNextEvent(everyEvent,&Event);
  174.     
  175.     where=FindWindow(Event.where,&inWindow);
  176.     
  177.     if (eventOK)
  178.         {
  179.             switch (Event.what) 
  180.                 {    case nullEvent        :break;
  181.                     case mouseDown        :{
  182.                                             switch (where) 
  183.                                                 {    
  184.                                                     case    inMenuBar       :doMenu(MenuSelect(Event.where));break;
  185.                                                     case    inSysWindow     :SystemClick(&Event,inWindow);break;
  186.                                                     case    inDesk          :break;
  187.                                                     default                    :ExecWindow(&Event,inWindow);break;
  188.                                                 }
  189.                                           };break;                                        
  190.                                           
  191.                     case keyDown          :
  192.                     case keyUp              :
  193.                     case autoKey          :{    
  194.                                             theChar  = Event.message & charCodeMask;
  195.                                             if ((Event.modifiers & cmdKey) != 0) 
  196.                                             doMenu(MenuKey(theChar));
  197.                                             else
  198.                                             if(inWindow!=NULL)
  199.                                              ExecWindow(&Event,inWindow);  
  200.                                           };break;
  201.                     case diskEvt        :
  202.                     case driverEvt        :break;
  203.                     case multiFinderEvt :if (FrontWindow()!=NULL) ExecWindow(&Event,FrontWindow());break;
  204.                     case activateEvt    :
  205.                     case updateEvt        :ExecWindow(&Event,Event.message);break;
  206.                 }
  207.         }
  208. }
  209.  
  210. /*
  211. ---------------------- the main() ...
  212. */
  213.  
  214. main()
  215. {
  216.     SetUpSystem();
  217.     SetUpVariables();
  218.     SetUpCursor();
  219.     SetUpMenus();
  220.     
  221.     while(notFinished)
  222.         {
  223.             doLoop();            
  224.         }
  225. }
  226.  
  227. /*
  228. ----------------------
  229. */
  230.     
  231.